/**
 * Created by wlc on 2018/4/16.
 */
$(document).ready(function(){
    //设置账号悬停和焦点样式
    $("#username").focusout(function(){
        $("#username").css("background-color","white");
        $("#username-icon").css("color","#c8c8c8");
    });
    $("#username").hover(function(){
        $("#username").css("background-color","beige");
        $("#username-icon").css("color","#45D0E7");
    },function(){
        if (!$("#username").is(":focus")){
            $("#username").css("background-color","white");
            $("#username-icon").css("color","#c8c8c8");
        }
    });
    //设置密码悬停和焦点样式
    $("#password").focusout(function(){
        $("#password").css("background-color","white");
        $("#password-icon").css("color","#c8c8c8");
    });
    $("#password").hover(function(){
        $("#password").css("background-color","beige");
        $("#password-icon").css("color","#45D0E7");
    },function(){
        if (!$("#password").is(":focus")){
            $("#password").css("background-color","white");
            $("#login-password-icon").css("color","#c8c8c8");
        }
    });
    //设置密码可见和不可见样式
    $("#password-icon").click(function () {
        if($("#password-icon")[0].className === "fa fa-lock fa-fw"){
            $("#password-icon")[0].className = "fa fa-unlock fa-fw";
            $("#password")[0].type="text";
        }else {
            $("#password-icon")[0].className = "fa fa-lock fa-fw";
            $("#password")[0].type="password";
        }
    });
    //设置通知栏
    notyf = new Notyf();
});


/**
 * 用户登录信息处理
 */
$(document).on("click",'#login-button', function(e){
    $('#login_username_info').remove();
    var username = trim($('#username')[0].value);
    var password = trim($('#password')[0].value);
    if (!isEmpty(username) && !isEmpty(password)){
        $.ajax({
            type: 'POST',
            url: '../home/login_userexist',
            data: {username:username,password:password},
            success: function (data) {
                if (data !== "false"){
                    $('#user_login_info')[0].value = data;
                    document.getElementById("login-submit").click();
                    notyf.confirm('登录成功！');
                }else {
                    notyf.alert('用户名或密码错误！');
                }
            }
        });
    }else {
        notyf.alert('用户名或密码不能为空！');
    }
});